package com.wiscamp.ninechapters.problems.infrastructure.po.sets;

import com.wiscamp.ninechapters.ddd.PersistenceObject;
import jakarta.persistence.*;
import lombok.Data;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.HashSet;

/**
 * 组题规则
 */
@Table(name = "regroup_rules")
@Data
@Entity
public class RegroupRulePO implements PersistenceObject {
    @Serial
    private static final long serialVersionUID = 294488664848063393L;

    /**
     * 规则编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "rule_id", insertable = false, nullable = false)
    private long ruleId = 0;

    /**
     * 规则代码
     */
    @Column(name = "rule_code")
    private String ruleCode = "";

    /**
     * 规则名称
     */
    @Column(name = "rule_name")
    private String ruleName = "";

    /**
     * 机构编号
     */
    @Column(name = "organization_id", nullable = false)
    private long organizationId = 0;

    /**
     * 学科编号
     */
    @Column(name = "subject_id", nullable = false)
    private long subjectId = 0;

    /**
     * 总题数
     */
    @Column(name = "problem_quantity")
    private int problemQuantity = 0;

    /**
     * 题分数（待删除）
     */
    @Column(name = "total_score", nullable = false)
    private int totalScore = 0;

    /**
     * 答题时限
     */
    @Column(name = "total_time_limit", nullable = false)
    private int totalTimeLimit = 0;

    /**
     * 是否真题
     */
    @Column(name = "true_problem", nullable = false)
    private boolean trueProblem = false;

    /**
     * 难度系数
     */
    @Column(name = "difficulty", nullable = false)
    private int difficulty = 0;

    /**
     * problem set type
     */
    @Column(name = "set_type_id", nullable = false)
    private int setTypeId = 0;

    /**
     * 包含标签规则
     */
    @Column(name = "has_tag_rule", nullable = false)
    private boolean hasTagRule = false;

    /**
     * 包含题型规则
     */
    @Column(name = "has_problem_type_rule", nullable = false)
    private boolean hasProblemTypeRule = false;

    /**
     * 包含知识点规则
     */
    @Column(name = "has_knowledge_point_rule", nullable = false)
    private boolean hasKnowledgePointRule = false;

    /**
     * 备注
     */
    @Column(name = "remark")
    private String remark = "";

    /**
     * 是否可用
     */
    @Column(name = "is_active", nullable = false)
    private boolean enabled = true;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private boolean deleted = false;

    /**
     * 创建用户
     */
    @Column(name = "created_by", nullable = false)
    private long creatorId = 0;

    /**
     * 创建时间
     */
    @Column(name = "created_time", nullable = false)
    private LocalDateTime creationTime;

    /**
     * 编辑用户
     */
    @Column(name = "modified_by")
    private long modifierId = 0;

    /**
     * 编辑时间
     */
    @Column(name = "modified_time")
    private LocalDateTime modificationTime;

    /**
     * 标签规则列表
     */
    //@Fetch(FetchMode.SUBSELECT)
    //@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    //@JoinColumn(name = "rule_id", nullable = false, insertable = false, updatable = false)
    @Transient
    private Collection<TagRulePO> tagRules = new HashSet<>();

    /**
     * 题型规则列表
     */
    //@Fetch(FetchMode.SUBSELECT)
    //@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    //@JoinColumn(name = "rule_id", nullable = false, insertable = false, updatable = false)
    @Transient
    private Collection<ProblemTypeRulePO> problemTypeRules = new HashSet<>();

    /**
     * 知识点规则列表
     */
    //@Fetch(FetchMode.SUBSELECT)
    //@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    //@JoinColumn(name = "rule_id", nullable = false, insertable = false, updatable = false)
    @Transient
    private Collection<KnowledgePointRulePO> pointRules = new HashSet<>();
}